package com.pzhu.dormitory.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pzhu.dormitory.dao.PositionDao;
import com.pzhu.dormitory.entity.BuildingEntity;
import com.pzhu.dormitory.entity.PositionEntity;
import com.pzhu.dormitory.service.PositionService;
import com.pzhu.dormitory.utils.PageUtils;
import com.pzhu.dormitory.utils.Query;
import com.pzhu.dormitory.vo.PositionVo;
import com.pzhu.dormitory.vo.RoomVo;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("positionService")
@AllArgsConstructor
public class PositionServiceImpl extends ServiceImpl<PositionDao, PositionEntity> implements PositionService {

    private final PositionDao positionDao;
    @Override
    public PageUtils<PositionEntity> queryPage(Map<String, Object> params) {
        QueryWrapper<PositionEntity> queryWrapper = new QueryWrapper<>();
        String position = (String) params.get("position");
        if (StringUtils.isNotBlank(position)) {
            queryWrapper.lambda().like(PositionEntity::getPosition, "%" + position + "%");
        }
        IPage<PositionEntity> page = this.page(
                new Query<PositionEntity>().getPage(params),
                queryWrapper
        );
        return new PageUtils<>(page);
    }

    @Override
    public PageUtils<PositionVo> queryPagePositionVo(Map<String, Object> params) {
        Page<PositionVo> page = new Query<PositionVo>().getPage(params);
        // 查询基本数据
        Page<PositionVo> roomVoPage = positionDao.queryPageVo(page, params);
        return new PageUtils<>(roomVoPage);
    }


}
